﻿namespace GoodAdmin.Web.Core;

/// <summary>
/// 作业管理
/// </summary>
[ApiDescriptionSettings("System", Tag = "作业管理")]
[Route("system/job")]
public class JobController(ISysJobService jobService) : IDynamicApiController
{
    private readonly ISysJobService _jobService = jobService;

    /// <summary>
    /// 获取作业分页列表
    /// </summary>
    [HttpGet("getPageJobDetail")]
    [DisplayName("获取作业分页列表")]
    public async Task<SqlSugarPagedList<JobDetailOutput>> GetPageJobDetail([FromQuery] JobDetailPageInput input)
    {
        return await _jobService.PageJobDetail(input);
    }

    /// <summary>
    /// 获取触发器列表
    /// </summary>
    [HttpGet("getJobTriggerList")]
    [DisplayName("获取触发器列表")]
    public async Task<List<SysJobTrigger>> GetJobTriggerList([FromQuery] JobDetailIdInput input)
    {
        return await _jobService.GetJobTriggerList(input);
    }

    /// <summary>
    /// 获取作业触发器运行记录分页列表
    /// </summary>
    [HttpGet("getPageJobTriggerRecord")]
    [DisplayName("获取作业触发器运行记录分页列表")]
    public async Task<SqlSugarPagedList<SysJobTriggerRecord>> GetPageJobTriggerRecord([FromQuery] JobTriggerRecordPageInput input)
    {
        return await _jobService.PageJobTriggerRecord(input);
    }

    /// <summary>
    /// 添加作业
    /// </summary>
    /// <returns></returns>
    [HttpPost("addJobDetail")]
    [DisplayName("添加作业")]
    public async Task AddJobDetail(JobDetailInput input)
    {
        await _jobService.AddJobDetail(input);
    }

    /// <summary>
    /// 更新作业
    /// </summary>
    /// <returns></returns>
    [HttpPost("updateJobDetail")]
    [DisplayName("更新作业")]
    public async Task UpdateJobDetail(JobDetailInput input)
    {
        await _jobService.UpdateJobDetail(input);
    }

    /// <summary>
    /// 删除作业
    /// </summary>
    /// <returns></returns>
    [HttpPost("deleteJobDetail")]
    [DisplayName("删除作业")]
    public async Task DeleteJobDetail(JobDetailIdInput input)
    {
        await _jobService.DeleteJobDetail(input);
    }

    /// <summary>
    /// 添加触发器
    /// </summary>
    /// <returns></returns>
    [HttpPost("addJobTrigger")]
    [DisplayName("添加触发器")]
    public async Task AddJobTrigger(JobTriggerInput input)
    {
        await _jobService.AddJobTrigger(input);
    }
    /// <summary>
    /// 更新触发器
    /// </summary>
    /// <returns></returns>
    [HttpPost("updateJobTrigger")]
    [DisplayName("更新触发器")]
    public async Task UpdateJobTrigger(JobTriggerInput input)
    {
        await _jobService.UpdateJobTrigger(input);
    }

    /// <summary>
    /// 删除触发器
    /// </summary>
    /// <returns></returns>
    [HttpPost("deleteJobTrigger")]
    [DisplayName("删除触发器")]
    public async Task DeleteJobTrigger(JobTriggerIdInput input)
    {
        await _jobService.DeleteJobTrigger(input);
    }

    /// <summary>
    /// 暂停所有作业
    /// </summary>
    /// <returns></returns>
    [HttpPost("pauseAllJob")]
    [DisplayName("暂停所有作业")]
    public void PauseAllJob()
    {
        _jobService.PauseAllJob();
    }

    /// <summary>
    /// 启动所有作业
    /// </summary>
    /// <returns></returns>
    [HttpPost("startAllJob")]
    [DisplayName("启动所有作业")]
    public void StartAllJob()
    {
        _jobService.StartAllJob();
    }

    /// <summary>
    /// 暂停作业
    /// </summary>
    [HttpPost("pauseJob")]
    [DisplayName("暂停作业")]
    public void PauseJob(JobDetailIdInput input)
    {
        _jobService.PauseJob(input);
    }

    /// <summary>
    /// 启动作业
    /// </summary>
    [HttpPost("startJob")]
    [DisplayName("启动作业")]
    public void StartJob(JobDetailIdInput input)
    {
        _jobService.StartJob(input);
    }

    /// <summary>
    /// 取消作业
    /// </summary>
    [HttpPost("cancelJob")]
    [DisplayName("取消作业")]
    public void CancelJob(JobDetailIdInput input)
    {
        _jobService?.CancelJob(input);
    }

    /// <summary>
    /// 执行作业
    /// </summary>
    /// <param name="input"></param>
    [HttpPost("runJob")]
    [DisplayName("执行作业")]
    public void RunJob(JobDetailIdInput input)
    {
        _jobService.RunJob(input);
    }

    /// <summary>
    /// 暂停触发器
    /// </summary>
    [HttpPost("pauseTrigger")]
    [DisplayName("暂停触发器")]
    public void PauseTrigger(JobTriggerIdInput input)
    {
        _jobService.PauseTrigger(input);
    }

    /// <summary>
    /// 启动触发器
    /// </summary>
    [HttpPost("startTrigger")]
    [DisplayName("启动触发器")]
    public void StartTrigger(JobTriggerIdInput input)
    {
        _jobService.StartTrigger(input);
    }

    /// <summary>
    /// 强制唤醒作业调度器
    /// </summary>
    [HttpPost("cancelSleep")]
    [DisplayName("强制唤醒作业调度器")]
    public void CancelSleep()
    {
        _jobService.CancelSleep();
    }

    /// <summary>
    /// 强制触发所有作业持久化
    /// </summary>
    [HttpPost("persistAll")]
    [DisplayName("强制触发所有作业持久化")]
    public void PersistAll()
    {
        _jobService.PersistAll();
    }    
}
